<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言与订阅管理</title>
    <link rel="stylesheet" href="../styles/styles-main.css">
    <link rel="stylesheet" href="../styles/modules.css">

    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="../modules/module-loader.js"></script>
    <script src="../modules/core-modules.js"></script>
    <script>
        // 动态加载留言管理所需模块
        document.addEventListener('DOMContentLoaded', async function() {
            try {
                await moduleLoader.loadModules([
                    ['api-client', '../scripts/api-client.js'],
                    ['navbar-main', '../scripts/navbar-main.js'],
                    ['sidebar-manager', '../scripts/sidebar-manager.js'],
                    ['messages', '../scripts/messages.js']
                ]);
                
                // 初始化留言管理
                if (typeof MessagesManager !== 'undefined') {
                    const messagesManager = new MessagesManager();
                    messagesManager.init();
                }
            } catch (error) {
                console.error('模块加载失败:', error);
            }
        });
    </script>
    <style>
        /* 留言订阅页面专用样式 */
        .messages-container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
        }

        .messages-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .header-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }

        .header-controls {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        .search-box {
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 250px;
            font-size: 14px;
            background: #fafafa;
        }

        .search-box:focus {
            outline: none;
            border-color: #007bff;
            background: #fff;
        }

        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .btn-primary {
            background: #007bff;
            color: white;
        }

        .btn-primary:hover {
            background: #0056b3;
        }

        .btn-secondary {
            background: #6c757d;
            color: white;
        }

        .btn-secondary:hover {
            background: #545b62;
        }

        .btn-danger {
            background: #dc3545;
            color: white;
        }

        .btn-danger:hover {
            background: #c82333;
        }

        /* 数据可视化统计卡片 */
        .stats-cards {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .stat-card {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .stat-icon {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            color: white;
        }

        .stat-content {
            flex: 1;
        }

        .stat-number {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }

        .stat-label {
            font-size: 14px;
            color: #666;
            margin: 0;
        }

        /* 图表容器 */
        .charts-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .chart-card {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .chart-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin-bottom: 15px;
        }

        .chart-canvas {
            width: 100%;
            height: 250px;
        }

        /* 左侧菜单 */
        .messages-sidebar {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            width: 200px;
            float: left;
            margin-right: 20px;
        }

        .menu-item {
            padding: 12px 15px;
            border-radius: 4px;
            cursor: pointer;
            margin-bottom: 5px;
            transition: all 0.2s;
            color: #666;
            text-decoration: none;
            display: block;
        }

        .menu-item:hover {
            background: #f8f9fa;
            color: #333;
        }

        .menu-item.active {
            background: #007bff;
            color: white;
        }

        /* 内容区域 */
        .messages-content {
            margin-left: 240px;
        }

        .content-section {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .section-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }

        /* 表格样式 */
        .data-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 14px;
        }

        .data-table th {
            background: #f8f9fa;
            padding: 12px 15px;
            text-align: left;
            font-weight: 600;
            color: #666;
            border-bottom: 1px solid #eee;
        }

        .data-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #eee;
            color: #333;
        }

        .data-table tr:hover {
            background: #f8f9fa;
        }

        .status-badge {
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 500;
        }

        .status-pending {
            background: #fff3cd;
            color: #856404;
        }

        .status-replied {
            background: #d4edda;
            color: #155724;
        }

        .status-subscribed {
            background: #d1ecf1;
            color: #0c5460;
        }

        .status-unsubscribed {
            background: #f8d7da;
            color: #721c24;
        }

        /* 操作按钮 */
        .action-buttons {
            display: flex;
            gap: 5px;
        }

        .btn-sm {
            padding: 4px 8px;
            font-size: 12px;
            border-radius: 3px;
        }

        /* 快速回复区域 */
        .quick-reply {
            display: none;
            background: #f8f9fa;
            border-radius: 4px;
            padding: 15px;
            margin-top: 10px;
        }

        .reply-input {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 10px;
            font-size: 14px;
            resize: vertical;
            min-height: 60px;
        }

        .reply-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        /* 分页 */
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            margin-top: 20px;
        }

        .page-btn {
            padding: 6px 12px;
            border: 1px solid #ddd;
            background: #fff;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }

        .page-btn.active {
            background: #007bff;
            color: white;
            border-color: #007bff;
        }

        .page-btn:hover:not(.active) {
            background: #f8f9fa;
        }

        /* 批量操作 */
        .batch-actions {
            display: none;
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            border-radius: 4px;
            padding: 10px 15px;
            margin-bottom: 15px;
        }

        .batch-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .messages-sidebar {
                width: 100%;
                float: none;
                margin-right: 0;
                margin-bottom: 15px;
            }

            .messages-content {
                margin-left: 0;
            }

            .header-controls {
                width: 100%;
                justify-content: space-between;
            }

            .search-box {
                width: 100%;
                margin-bottom: 10px;
            }

            .data-table {
                font-size: 12px;
            }

            .data-table th,
            .data-table td {
                padding: 8px 10px;
            }

            .stats-cards {
                grid-template-columns: 1fr;
            }

            .charts-container {
                grid-template-columns: 1fr;
            }
        }

        /* 选中状态 */
        .row-selected {
            background: #e3f2fd !important;
        }

        .checkbox {
            width: 16px;
            height: 16px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
            </ul>
        </nav>
        
        <main class="content">
            <div class="messages-container">
                <!-- 顶部导航栏 -->
                <div class="messages-header">
                    <h1 class="header-title">留言与订阅管理</h1>
                    <div class="header-controls">
                        <input type="text" class="search-box" placeholder="搜索留言或订阅者..." id="searchInput">
                        <button class="btn btn-secondary" onclick="toggleBatchActions()">
                            <i class="fas fa-check-square"></i> 批量操作
                        </button>
                        <button class="btn btn-primary" onclick="exportData()">
                            <i class="fas fa-download"></i> 导出数据
                        </button>
                    </div>
                </div>

                <!-- 批量操作面板 -->
                <div class="batch-actions" id="batchActions">
                    <div class="batch-info">
                        <span>已选择 <span id="selectedCount">0</span> 个项目</span>
                        <div>
                            <button class="btn btn-sm btn-danger" onclick="batchDelete()">批量删除</button>
                            <button class="btn btn-sm btn-secondary" onclick="toggleBatchActions()">取消</button>
                        </div>
                    </div>
                </div>

                <!-- 数据可视化统计 -->
                <div class="stats-cards" id="statsCards">
                    <!-- 统计卡片将通过JavaScript动态生成 -->
                </div>

                <!-- 数据可视化图表 -->
                <div class="charts-container" id="chartsContainer">
                    <!-- 图表将通过JavaScript动态生成 -->
                </div>

                <!-- 左侧精简菜单 -->
                <div class="messages-sidebar">
                    <a href="#messages" class="menu-item active" onclick="showSection('messages')">
                        留言管理
                    </a>
                    <a href="#subscriptions" class="menu-item" onclick="showSection('subscriptions')">
                        订阅管理
                    </a>
                </div>

                <!-- 内容区域 -->
                <div class="messages-content">
                    <!-- 留言管理 -->
                    <div class="content-section" id="messagesSection">
                        <div class="section-header">
                            <h2 class="section-title">留言列表</h2>
                            <div class="filters">
                                <select class="btn btn-secondary" onchange="filterMessages(this.value)">
                                    <option value="all">全部状态</option>
                                    <option value="pending">待回复</option>
                                    <option value="replied">已回复</option>
                                </select>
                            </div>
                        </div>

                        <table class="data-table">
                            <thead>
                                <tr>
                                    <th width="30"><input type="checkbox" class="checkbox" onchange="toggleSelectAll(this)"></th>
                                    <th width="120">客户姓名</th>
                                    <th width="150">邮箱地址</th>
                                    <th width="100">联系电话</th>
                                    <th width="120">留言主题</th>
                                    <th>留言内容</th>
                                    <th width="120">时间</th>
                                    <th width="80">状态</th>
                                    <th width="100">操作</th>
                                </tr>
                            </thead>
                            <tbody id="messagesTable">
                                <!-- 留言数据将通过JavaScript动态加载 -->
                            </tbody>
                        </table>

                        <!-- 分页 -->
                        <div class="pagination" id="messagesPagination">
                            <!-- 分页按钮将通过JavaScript动态生成 -->
                        </div>
                    </div>

                    <!-- 订阅管理 -->
                    <div class="content-section" id="subscriptionsSection" style="display: none;">
                        <div class="section-header">
                            <h2 class="section-title">订阅列表</h2>
                            <div class="filters">
                                <select class="btn btn-secondary" onchange="filterSubscriptions(this.value)">
                                    <option value="all">全部状态</option>
                                    <option value="subscribed">已订阅</option>
                                    <option value="unsubscribed">已取消</option>
                                </select>
                            </div>
                        </div>

                        <table class="data-table">
                            <thead>
                                <tr>
                                    <th width="30"><input type="checkbox" class="checkbox" onchange="toggleSelectAll(this)"></th>
                                    <th width="120">客户姓名</th>
                                    <th width="150">邮箱地址</th>
                                    <th width="100">联系电话</th>
                                    <th width="150">联系地址</th>
                                    <th width="120">订阅时间</th>
                                    <th width="80">状态</th>
                                    <th width="120">操作</th>
                                </tr>
                            </thead>
                            <tbody id="subscriptionsTable">
                                <!-- 订阅数据将通过JavaScript动态加载 -->
                            </tbody>
                        </table>

                        <!-- 分页 -->
                        <div class="pagination" id="subscriptionsPagination">
                            <!-- 分页按钮将通过JavaScript动态生成 -->
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- 模块化加载已在head部分完成 -->
</body>
</html>